<%= render Settings::H1Component.new do %>
  Import & Export
<% end %>

<%= form_with model: Import.new, url: settings_imports_path do |f| %>
  <%= render Settings::ControlGroupComponent.new class: "mb-14" do |group| %>
    <% group.header do %>
      Import
    <% end %>
    <% group.item do %>
      <%= render Settings::ControlRowComponent.new do |row| %>
        <% row.title do %>
          <%= f.file_field :upload, accept: ".xml, .opml, text/xml, application/xml, text/x-opml, text/x-opml+xml", class: "file:appearance-none file:border-solid file:text-sm file:font-medium file:relative file:inline-flex file:items-center file:justify-center file:gap-2 file:p-0 file:border file:border-500 file:whitespace-nowrap file:leading-[42px] file:px-6 file:rounded-md file:text-700 file:bg-transparent file:transition file:transition-[box_shadow] file:cursor-pointer file:hover:shadow-one file:active:bg-100 file:active:hover:shadow-none" %>
        <% end %>
        <% row.description do %>
          <div class="mt-1">You can import OPML files.</div>
        <% end %>
        <% row.control do %>
          <button type="submit" class="button">Import</button>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
<% end %>

<%= render Settings::ControlGroupComponent.new class: "mb-14" do |group| %>
  <% group.header do %>
    Export
  <% end %>
  <% group.item do %>
    <%= form_tag subscriptions_path(format: :xml), method: :get do %>
      <%= render Settings::ControlRowComponent.new do |row| %>
        <% row.title { "Subscriptions" } %>
        <% row.control do %>
          <%= render Form::SelectInputComponent.new do |input| %>
            <% input.input do %>
              <%= select_tag :tag, options_for_select(@download_options), class: "peer" %>
            <% end %>
          <% end %>
          <button class="button">Download</button>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
  <% if @user.starred_entries.exists? %>
    <% group.item do %>
      <%= render Settings::ControlRowComponent.new do |row| %>
        <% row.title { "Starred Articles" } %>
        <% row.description { "A link will be emailed to you." } %>
        <% row.control do %>
          <%= link_to "Export", starred_export_path, method: :post, class: "button" %>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
<% end %>

<% if @imports.present? %>
  <%= render Settings::ControlGroupComponent.new class: "mb-14" do |group| %>
    <% group.header do %>
      Import History
    <% end %>

    <% @imports.each do |import| %>
      <% group.item do %>
        <%= render Settings::ControlRowComponent.new do |row| %>
          <% row.title { import.created_at.to_formatted_s(:date) } %>
          <% row.description { import.filename } %>
          <% row.control do %>
            <%= link_to "Details", settings_import_path(import) %>
          <% end %>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
<% end %>